const router = require('koa-router')()
import Token from '../prototype/token'
// import router from 'koa-router'

// router.prefix('/test')


exports = router.get('/', async (ctx, next) => {
    let url = ctx.url
    // 从上下文的request对象中获取
    let request = ctx.request
    let req_query = request.query
    let req_querystring = request.querystring

    // 从上下文中直接获取
    let ctx_query = ctx.query
    let ctx_querystring = ctx.querystring
    ctx.body = {
      url,
      req_query,
      req_querystring,
      ctx_query,
      ctx_querystring
    }
  })


router.get('/token', async (ctx, next) => {
  const token = new Token()
  // 前端访问时会附带token在请求头
  const payload = await token.getJWTPayload(ctx.headers.authorization)
  ctx.body = {
    token: payload
  }
})

module.exports = router
